<template>
  <div class="outermostLayer">
    <div style="display: flex; width: 80%; flex-wrap: wrap;">
      <div class="container" v-for="(item, index) in jobPostings" :key="index" title="点击可查看详情"
        @click="toDetail(item.id)">
        <div class="header">
          <div class="block" style="margin-right: 20px; height: 50px">
            <el-avatar :size="80" :src="item.logo" />
          </div>
          <div class="right">
            <div class="company-name">{{ item.companyName }}</div>
            <div style="display: flex;flex-direction: column;width: 100%;">
              <div style="display: flex;align-items: center">
                <div class="positionName">{{ item.positionName }}</div>
                <div class="position">{{ item.respPos }}</div>
              </div>
              <div style="display: flex;margin-top: 10px;margin-bottom: 10px;align-items: center">
                <div class="year">{{ item.experience }}</div>
                <div class="education">{{ item.education }}</div>
              </div>
              <div style="display: flex;">
                <div class="salary">{{ item.salary }}</div>
                <div class="place">
                  {{ item.province }} <span v-if="item.province">-</span>
                  {{ item.city }} <span v-if="item.street">-</span>
                  {{ item.street }}
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="footer">
          <div class="classify">
            <ul>
              <li v-for="(item, index) in item.industryType" :key="index">
                {{ item }}
              </li>
            </ul>
          </div>
          <div class="descibe">
            {{ item.content }}
          </div>
          <div class="detel" @click="deJobpostings(item.id)">
            <div class="loveTitle">删除</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 发布新岗位 -->
    <div style="display: flex;flex-direction: column;width:20%">
      <div class="card" id="fbht" @click="$router.push('/jobRecommendation/pushPosition')">
        发布新职位
      </div>
      <div class="hot-topic">
        <h3>职位排行榜</h3>
        <!-- <div class="time">更新于：{{ currentTime }}</div> -->
        <div class="content">
          <ul>
            <li v-for="(item, index) in postRanking" :key="index">
              <span style="margin: 10px;">{{ item.rank }}</span>
              <span>{{ item.positionName }}</span>
              <!-- <span>{{ item.readCount }}</span> -->
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div style="display: flex; justify-content: center; width: 100%">
      <el-pagination v-model:current-page="currentPage" :hide-on-single-page="true" :page-size="12" :size="size"
        :background="true" layout="total, prev, pager, next" :total="total" @current-change="handleCurrentChange" />
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import type { ComponentSize } from "element-plus";
import { ElMessage } from "element-plus";
import { getJobPosting, deletejobPostings, getJobPostingsRank } from "@/api/position";
import { useRouter } from "vue-router";

const router = useRouter();

//分页数据
const currentPage = ref(1);
const total = ref(0);
const size = ref<ComponentSize>("default");

//获取职位推荐信息
const jobPostings = ref([]);
const queryJobPositings = async () => {
  const res = await getJobPosting(currentPage.value, 9, "", "");
  jobPostings.value = res.data.list;
  total.value = res.data.total;
  // jobPostings.value = res;
};
queryJobPositings();

//删除帖子
const deJobpostings = async (id) => {
  const res = await deletejobPostings(id);
  if (res.code === 200) {
    ElMessage.success("删除成功");
    queryJobPositings();
  } else {
    ElMessage.success("删请检查网络问题，稍后重试");
  }
};

//分页变化
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  currentPage.value = val;
  queryJobPositings();
};

const toDetail = (id: number) => {
  router.push(`/jobRecommendation/jobDetails?id=${id}`);
};


const postRanking = ref([])  //帖子排名

const rank = async () => {
  const res = await getJobPostingsRank();
  if (res.code == 200) {
    console.log("排行查询成功");
    postRanking.value = res.data;
    console.log(res.data);

  }
}
rank();
</script>

<style lang="scss" scoped>
ul {
  padding-left: 0;
  list-style-type: none;
}

.outermostLayer {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  min-height: 90vh;
}

.container {
  display: flex;
  flex-direction: column;
  padding: 20px;
  border: 1px solid #ccc;
  width: 300px;
  //   box-shadow: 20px 20px 50px #000;
  /* filter: blur(6px); */
  background: rgba(89, 165, 245, 0.2);
  backdrop-filter: blur(10px);
  border-top: 1px solid #ffffff50;
  border-left: 1px solid #ffffff50;
  border-radius: 15px;
  margin-left: 20px;
  margin-bottom: 20px;
  cursor: pointer;
}

.container:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.header {
  display: flex;
}

.right {
  width: 77%;
  display: flex;
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.logo {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  width: 70px;
  height: 70px;
  background-color: #ccc;
  border-radius: 50%;
  margin-right: 20px;
}

.company-name {
  color: #4D4D4D;
  width: 100%;
  font-size: 20px;
  margin-bottom: 10px;
}

.header .right .position,
.header .right .year {
  width: calc(50% - 10px);
  box-sizing: border-box;
  color: #5c5c5c;
}

.header .right .year {
  width: 83%;
}


.positionName {
  box-sizing: border-box;
  color: #5c5c5c;
  width: 83%;
}

.middle {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.place {
  margin-bottom: 10px;
  box-sizing: border-box;
  color: #5c5c5c;
}

.middle .right {
  width: 71%;
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 10px;
  box-sizing: border-box;
}

.education {
  width: calc(50% - 10px);
  box-sizing: border-box;
  color: #5c5c5c;
}

.salary {
  width: 64%;
  color: #5c5c5c;
  box-sizing: border-box;
}

.footer {
  display: flex;
  justify-content: space-between;
}

.footer .classify {
  width: 29%;
  padding: 10px;
  box-sizing: border-box;
  color: #333;
}

.footer .descibe {
  color: #333;
  width: 71%;
  padding: 5px;
  box-sizing: border-box;
  display: -webkit-box;
  -webkit-line-clamp: 7;
  /* 限制显示 6 行 */
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

//发布新岗位按钮
#fbht {
  background: linear-gradient(to right,
      #00bfff,
      /* 起始颜色 */
      rgba(0, 191, 255, 0.8) 50%,
      /* 渐变中间，稍微透明 */
      rgba(0, 191, 255, 0.4) 100%
      /* 结束颜色，更透明 */
    );
  text-align: center;
  color: white;
  font-weight: bold;
  border-radius: 10px;
  box-shadow: 2px 4px 5px lightgray;
  cursor: pointer;
}

.card {
  display: flex;
  // margin-top: 2vh;
  height: 5vh;
  padding: 3% 7%;
  align-items: center;
  justify-content: center;
}

.card p {
  margin: 0;
}

.detel {
  width: 50px;
  height: 30px;
  margin: 10px;
  padding: 5px;
  border-radius: 10px;
  border: 1px solid red;
  color: red;
  background: transparent;
  text-align: center;
  line-height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.detel:hover {
  background-color: red;
  color: #fff;
}

//热搜榜
.hot-topic {
  border: 1px solid lightgrey;
  box-shadow: 2px 2px 6px lightgray;
  border-radius: 15px;
  width: 100%;
  // height: 500px;
  margin-top: 30px;
  // margin-left: -45px;
}

.hot-topic h3 {
  font-size: 20px;
  color: #333;
  text-align: center;
  background-color: #fff;
  margin: 10px 0;
  margin-top: 0;
  border-radius: 10px 10px 0 0;
  height: 40px;
  line-height: 40px;
}

.hot-topic .time {
  // height: 14px;
  font-size: 16px;
  margin: 5px 20px;
}

.hot-topic .content ul {
  list-style: none;
  padding: 0px;
  margin-top: -10px;
}

.hot-topic .content ul li {
  height: 45px;
  font-size: 16px;
  border-bottom: 1px dotted #ddd;
  display: flex;
  align-items: center;
  justify-content: space-around;
  color: #333;
  padding: 5px;
}

.hot-topic .content ul li:nth-child(odd) {
  background-color: #d4eaf7;
}

.hot-topic .content ul li:nth-child(even) {
  background-color: #71c4ef;
}

.hot-topic span:nth-child(2) {
  width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.hot-topic span:nth-child(2) p {
  width: 240px;
  height: 45px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.hot-topic li:nth-child(1) span:nth-child(1) {
  color: red;
  font-weight: bold;
}

.hot-topic li:nth-child(2) span:nth-child(1) {
  color: #ff5c55;
  font-weight: bold;
}

.hot-topic li:nth-child(3) span:nth-child(1) {
  color: #ffa552;
  font-weight: bold;
}

.hot-topic .content ul li:last-child {
  border-radius: 0 0 8px 8px;
  margin-bottom: 0;
}
</style>
